clear
set more off
capture log close

*******************************
*** SET WORKING DIRECTORIES ***
*******************************
	
	if "`c(username)'" == "XXXXX" {
		global Rterm_path `"XXXXXX"'	// Point this to your rterm path (see note below)
		global root "XXXXXX"			// Point this to the "Replication_Files" folder
		global output "XXXXXX"      	// Point this to the "Replication_Output" folder
	}
	
/*

Rterm_path pathway varies by Operating System, e.g.
	Windows:
	"C:\Program Files\R\R-4.0.2\bin\R.exe"
	Mac:
	"/usr/local/bin/R"

*/

* For example (Mac):

	if "`c(username)'" == "jimmy" {
		global Rterm_path "/usr/local/bin/R"
		global root "~/Dropbox/SMS_ADMIN/Replication Package v1.0.8/Replication_Files"
		global output "~/Dropbox/SMS_ADMIN/Replication Package v1.0.8/Replication_Output"
	}

global smscode "$root/CODE/Replication_Code"
global covidclean "$output/Cleaned_Data"
global treatment = "$root/DATA/Treatment_Assignments"
global tables = "$output/Tables"
global logfiles = "$output/Log_Files"
global figures = "$output/Figures"
global dofiles = "$root/CODE/Replication_Code"
global rianalysis = "$output/Randomization_Inference"	
global covidraw "$root/DATA/Raw_Survey_Data"
global deliveryreports "$root/DATA/Delivery_Reports"



********************************
*** SET GLOBALS FOR ANALYSIS ***
********************************

	***CONTROLS FOR THE STUDY DESIGN
		global studycontrols stratum roundofinterview behavior_sd dayofinterview blockid enumerator know_behavior_order 
		global covariates male occupation age education location
		global sample "(interviewlag==3 | interviewdelta==0)"
		global nbatch 36   // <--------- CHANGE THIS NUMBER TO EDIT THE NUMBER OF RANDOMIZATION INFERENCE LOOPS
		
	***Treatments
		global treat_pool treatment_pooled
		global treat_pool_sd treatment_pooled_sd
		global treat_pool_hw treatment_pooled_hw
		
		global treat_frames treatment_frame_2 treatment_frame_3 treatment_frame_4 treatment_frame_5 treatment_frame_6
		global treat_frames_sd treatment_frame_2_sd treatment_frame_3_sd treatment_frame_4_sd treatment_frame_5_sd treatment_frame_6_sd
		global treat_frames_hw treatment_frame_2_hw treatment_frame_3_hw treatment_frame_4_hw treatment_frame_5_hw treatment_frame_6_hw
		
		global treat_timings treatment_timing_2 treatment_timing_3
		global treat_timings_sd treatment_timing_2_sd treatment_timing_3_sd
		global treat_timings_hw treatment_timing_2_hw treatment_timing_3_hw
		
		global treat_arms treatment_arm_2 treatment_arm_3 treatment_arm_4 treatment_arm_5 treatment_arm_6 treatment_arm_7 treatment_arm_8 treatment_arm_9 treatment_arm_10 treatment_arm_11
		global treat_arms_sd treatment_arm_2_sd treatment_arm_3_sd treatment_arm_4_sd treatment_arm_5_sd treatment_arm_6_sd treatment_arm_7_sd treatment_arm_8_sd treatment_arm_9_sd treatment_arm_10_sd treatment_arm_11_sd
		global treat_arms_hw treatment_arm_2_hw treatment_arm_3_hw treatment_arm_4_hw treatment_arm_5_hw treatment_arm_6_hw treatment_arm_7_hw treatment_arm_8_hw treatment_arm_9_hw treatment_arm_10_hw treatment_arm_11_hw
		
		
********************************
*** INSTALL/UPDATE COMMANDS ***
********************************

	foreach x in reghdfe outreg matsave texsave winsor2 ivreg2 ranktest ivreghdfe keeporder unique blindschemes gtools rsource stratarand ftools {
		capture findfile `x'.ado		
		if _rc==601 {
			ssc install `x'
		}
	} 

	capture findfile frmttable.ado		
	if _rc==601 {
		net install sg97_5
	}
	
	capture findfile grc1leg.ado		
	if _rc==601 {
		net install grc1leg.pkg
	}


********************************
*** RUN REPLICATION DO FILES ***
********************************


****** CLEANING STEPS ******

run "$smscode/01_data_merging.do"
run "$smscode/02_data_cleaning.do"

****** POSTERIOR PROBABILITIES ******

run "$smscode/03_posterior_probabilities.do"

****** RANDOMIZATION INFERENCE ******

* generate RI Data file
run "$smscode/04a_randomization_inference.do"

run "$smscode/04a_ri_merge.do"

****** ANALYSIS ******

run "$smscode/04b_analysis_descriptives.do"
run "$smscode/04b_analysis_itt.do"
run "$smscode/04b_analysis_firststage.do"
run "$smscode/04b_analysis_itt_hetero.do"
run "$smscode/04b_analysis_itt_spill.do"
run "$smscode/04b_analysis_treatmentshares.do"
run "$smscode/04b_analysis_itt_sds.do"
run "$smscode/04b_analysis_itt_risks.do"
run "$smscode/04b_analysis_figures.do"
run "$smscode/04b_analysis_2sls.do"
run "$smscode/04b_analysis_itt_controlstest.do"












